﻿using MxWeiXinPF.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MxWeiXinPF.Web.shop
{
    public partial class userchild : MxWeiXinPF.Web.UI.UserPage
    {
        public string carturl = "";
        public string indexurl = "";
        protected int page;
        protected int pageSize;
        protected int totalCount;
        public string url = "";
        public string userinfourl = "";
        public string categoryurl = "";
        protected string CombSqlTxt(string openid)
        {
            StringBuilder builder = new StringBuilder();
            if (!string.IsNullOrEmpty(openid))
            {
                builder.Append(" and parentopenid='" + openid + "'");
            }
            return builder.ToString();
        }

        private int GetPageSize(int _default_size)
        {
            int num;
            if (int.TryParse(Utils.GetCookie("userchild"), out num) && (num > 0))
            {
                return num;
            }
            return _default_size;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            base.wid = MyCommFun.RequestInt("wid");
            base.openid = MyCommFun.RequestOpenid();
            this.indexurl = string.Concat(new object[] { "index.aspx?wid=", base.wid, "&openid=", this.openid, "&shopid=", shopid });
            this.carturl = string.Concat(new object[] { "cart.aspx?wid=", base.wid, "&openid=", this.openid, "&shopid=", shopid });
            this.userinfourl = string.Concat(new object[] { "userinfo.aspx?wid=", base.wid, "&openid=", this.openid, "&shopid=", shopid });
            this.categoryurl = MyCommFun.urlAddOpenid("/shop/category.aspx?wid=" + base.wid + "&shopid=" + shopid, base.openid);
            MxWeiXinPF.BLL.users users = new MxWeiXinPF.BLL.users();
            this.RptBind("id>0" + this.CombSqlTxt(base.openid), "id desc");
        }

        private void RptBind(string _strWhere, string _orderby)
        {
            try
            {
                this.page = MXRequest.GetQueryInt("page", 1);
                this.rptList.DataSource = new MxWeiXinPF.BLL.users().GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
                this.rptList.DataBind();
                this.txtPageNum.Text = this.pageSize.ToString();
                string linkUrl = Utils.CombUrlTxt("userchild.aspx", "parentopenid={0}", new string[] { base.openid });
                this.PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, linkUrl, 8);
            }
            catch (Exception ex)
            {

            }

        }

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int num;
            if (int.TryParse(this.txtPageNum.Text.Trim(), out num) && (num > 0))
            {
                Utils.WriteCookie("userchild", num.ToString(), 0x3840);
            }
            base.Response.Redirect(Utils.CombUrlTxt("userchild.aspx", "parentopenid={0}", new string[] { base.openid }));
        }
    }
}